"""
@Author: marco
@Date: 2021-6-17 14:23:08
@LastEditors  : marco
@LastEditTime : 2021-6-17 14:23:08
"""
import sys
import traceback

from flask import jsonify, make_response

from app.utils.logger import Logger
from app.utils.common import CommonUtil


def exception_api(code, e):
    """ 接口异常处理 """
    exc_type, exc_value, exc_traceback = sys.exc_info()
    Logger.error_log().logger.exception(e)
    body = {'code': code, 'msg': '接口处理异常', 'debug_id': CommonUtil.unique_id(),
            'traceback': traceback.format_exception(exc_type, exc_value, exc_traceback)}
    # dBSession.close()
    # 这里exc_type 和exc_value信息重复，所以不打印
    return make_response(jsonify(body))
